<html>
  <head>
    <title>Panel Transform</title>
    <script type="text/javascript" src="../../protovis.js"></script>
  </head>
  <body>
    <script type="text/javascript+protovis">

var w = 800,
    h = 800,
    t = pv.Transform.identity, // the inverted transform
    x = pv.Scale.linear(0, w).range(0, w),
    y = pv.Scale.linear(0, h).range(0, h);

var vis = new pv.Panel()
    .width(w)
    .height(h)
    .top(30)
    .left(40)
    .right(20)
    .bottom(20)
    .strokeStyle("#ccc");

vis.add(pv.Rule)
    .data(function() x.domain(t.x, w * t.k + t.x).ticks())
    .strokeStyle("#ccc")
    .left(x)
  .anchor("bottom").add(pv.Label);

vis.add(pv.Rule)
    .data(function() y.domain(t.y, h * t.k + t.y).ticks())
    .strokeStyle("#ccc")
    .top(y)
  .anchor("left").add(pv.Label);

var view = vis.add(pv.Panel)
    .overflow("hidden")
    .events("all")
    .event("mousedown", pv.Behavior.pan().bound(true))
    .event("mousewheel", pv.Behavior.zoom().bound(true));

view.add(pv.Dot)
    .data(pv.range(100).map(function() ({x:Math.random(), y:Math.random()})))
    .left(function(d) d.x * w)
    .top(function(d) d.y * h)
    .fillStyle(pv.rgb(255, 255, 255, .5))
    .radius(function() 5 / this.scale);

/* Hack! Need a way get the transform as it is set. */
view.transform = function() {
  var f = view.transform;
  return function(v) {
    if (v) t = v.invert();
    return f.apply(this, arguments);
  };
}();

/* Hack! Need a way to control which panel gets rendered with pan & zoom! */
view.render = function() {
  vis.render();
};

vis.render();

    </script>
  </body>
</html>
